import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/pages/home/home_most_page.dart';
import 'package:xiongan_app_yy/pages/home/home_single_page.dart';
import 'package:xiongan_app_yy/provider/fab_new_provider.dart';
import 'package:xiongan_app_yy/provider/index_model.dart';
import 'package:xiongan_app_yy/provider/warehouse_info.dart';
import 'package:xiongan_app_yy/widgets/comm/horizontal_list_home_widget.dart';

//预约类型首页第一个页面
class AppointmentPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return AppointmentPageState();
  }
}

class AppointmentPageState extends State<AppointmentPage> {
  Widget _widget;
  List imageList = [
    "assets/images/info.png",
    "assets/images/appointment.png",
    "assets/images/task.png",
  ];
  List titleList = ["待审批", "审批通过", "审批拒绝"];

  List routeList = [
    "/outvList",
    "/delivery_list",
    "/return_booking",
    "/invList",
    '/deployment_list'
  ];

  List routeFabList = [
    "/outvListNew",
    "/delivery_list_page_new",
    "/return_booking_new",
    "/invListNew",
    '/deployment_list_page_new'
  ];
  IndexModel model = IndexModel();

  @override
  void initState() {
    super.initState();
    if (DataSingleton()
            .Data
            .appModuleMenusList[0]
            .menuTreeDto
            .nezadaTreeList[0]
            .nodeName ==
        "出库预约") {
      model.setIndex(0);
    } else if (DataSingleton()
            .Data
            .appModuleMenusList[0]
            .menuTreeDto
            .nezadaTreeList[0]
            .nodeName ==
        "配送预约") {
      model.setIndex(1);
    } else if (DataSingleton()
            .Data
            .appModuleMenusList[0]
            .menuTreeDto
            .nezadaTreeList[0]
            .nodeName ==
        "结余退库") {
      model.setIndex(2);
    } else if (DataSingleton()
            .Data
            .appModuleMenusList[0]
            .menuTreeDto
            .nezadaTreeList[0]
            .nodeName ==
        "入库预约") {
      model.setIndex(3);
    } else if (DataSingleton()
            .Data
            .appModuleMenusList[0]
            .menuTreeDto
            .nezadaTreeList[0]
            .nodeName ==
        "调配预约") {
      model.setIndex(4);
    }
    if (DataSingleton()
            .Data
            .appModuleMenusList[0]
            .menuTreeDto
            .nezadaTreeList
            .length ==
        1) {
      _widget = HomeSinglePage(DataSingleton()
          .Data
          .appModuleMenusList[0]
          .menuTreeDto
          .nezadaTreeList[0]
          .nodeName);
    } else {
      _widget = new ScopedModel(
          model: model,
          child: HomeMostPage(DataSingleton()
              .Data
              .appModuleMenusList[0]
              .menuTreeDto
              .nezadaTreeList));
    }
    model.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Container(
            height: 205,
            width: double.infinity,
            child: Stack(
              children: <Widget>[
                Image.asset(
                  "assets/images/real_background.png",
                  fit: BoxFit.fill,
                  width: double.infinity,
                ),
                Column(
                  children: <Widget>[
                    Container(
                      margin: EdgeInsets.only(top: 32, left: 15, right: 7),
                      child: Row(
                        children: <Widget>[
                          GestureDetector(
                            child: Container(
                                height: 23,
                                padding: EdgeInsets.only(left: 6),
                                decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(10.0)),
                                    border: Border.all(
                                        width: 1,
                                        color: Colors.white) //设置所有的边框宽度为1 颜色为浅灰
                                    ),
                                child: Row(
                                  children: <Widget>[
                                    Text(
                                        Provider.of<WarehouseInfo>(context)
                                            .mode
                                            .text,
                                        style: TextStyle(fontSize: 13)),
                                    IconTheme(
                                      data: IconThemeData(),
                                      child: Icon(Icons.arrow_drop_down),
                                    ),
                                  ],
                                )),
                            onTap: () {
                              Navigator.pushNamed(
                                      context, "/warehouseSelection")
                                  .then((value) {});
                            },
                          ),
                          Expanded(
                            flex: 1,
                            child: Text(""),
                          ),
                          Row(
                            children: <Widget>[
                              Container(
                                  width: 28,
                                  height: 26,
                                  child: Image.asset("assets/images/cloudy.png",
                                      fit: BoxFit.fill)),
                              Text("0°",
                                  style: TextStyle(
                                      color: Colors.white, fontSize: 30)),
                              Column(
                                children: <Widget>[
                                  Text("雄安新区",
                                      style: TextStyle(
                                          fontSize: 10, color: Colors.white)),
                                  Text(
                                      "${DateTime.now().month}月${DateTime.now().day}日",
                                      style: TextStyle(
                                          fontSize: 10, color: Colors.white)),
                                ],
                              )
                            ],
                          )
                        ],
                      ),
                    ),
                    Expanded(
                        child: Column(
                      children: <Widget>[
                        Text("储检配一体化管理平台",
                            style: TextStyle(fontSize: 23, color: Colors.white))
                      ],
                      mainAxisAlignment: MainAxisAlignment.center,
                    )),
                  ],
                )
              ],
            ),
          ),
          Container(
              width: double.infinity,
              height: 120,
              color: Colors.white,
              child: Row(
                children: <Widget>[
                  Expanded(
                      child: HorizontalListHomeWidget(
                          modular: "主菜单",
                          arguments: 0,
                          title: titleList[0],
                          image: imageList[0],
                          route: routeList[model.count],
                          margin: EdgeInsets.only(right: 0.5),
                          background: Color(0xff00A5F1))),
                  Expanded(
                      child: HorizontalListHomeWidget(
                          modular: "主菜单",
                          arguments: 1,
                          title: titleList[1],
                          image: imageList[1],
                          route: routeList[model.count],
                          margin: EdgeInsets.only(right: 0.5),
                          background: Color(0xff00A5F1))),
                  Expanded(
                      child: HorizontalListHomeWidget(
                          modular: "主菜单",
                          arguments: 2,
                          title: titleList[2],
                          image: imageList[2],
                          route: routeList[model.count],
                          background: Color(0xff00A5F1)))
                ],
              )),
          Expanded(child: _widget)
        ],
      ),
      floatingActionButton: FloatingActionButton(
          onPressed: () {
            Navigator.pushNamed(context, routeFabList[model.count])
                .then((value) {
              if (value == "ok") {
                Provider.of<FabNewProvider>(context).setIndex(model.count);
              }
            });
          },
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Image.asset(
                "assets/images/add_appointment.png",
                fit: BoxFit.fill,
                height: 20,
                width: 16,
              ),
              Text("新建"),
            ],
          )),
    );
  }
}
